﻿using JzSport.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JzSport.Api
{
    /// <summary>
    /// 获取个人的推广活动列表
    /// </summary>
    class GetPromotionalActivityListAction : GetAction<Params.GetPromotionalActivityListParams,
        Results.GetPromotionalActivityListResult>
    {
        public static string[] paarr = new string[]{
            "./Res/pap01.jpg",
            "./Res/pap02.jpg",
            "./Res/pap03.jpg"
        };

        protected override ActionResult<Results.GetPromotionalActivityListResult> OnExecute(ActionContext context,
            SysParameters sysParameters,
            Params.GetPromotionalActivityListParams opParams)
        {
            int limit = 10;
            int start = opParams.Page * limit;
            Results.GetPromotionalActivityListResult actionResult = new Results.GetPromotionalActivityListResult();
            actionResult.Start = 0;
            actionResult.Limit = 5;
            actionResult.Total = paarr.Length;
            actionResult.IsTheEnd = true;

            for (int index = 0; index < paarr.Length; index++)
            {
                Results.GetPromotionalActivityListResult.Item item = new Results.GetPromotionalActivityListResult.Item();
                item.Id = Guid.NewGuid();
                item.CreatedTime = DateTime.Now;
                item.BeginTime = DateTime.Now;
                item.EndTime = DateTime.Now.AddDays(5);
                item.Title = string.Format("推广活动{0}", item.Id.ToString());
                item.PreviewImageUrl = string.Format("{0}{1}", Configs.BaseWebUrl, paarr[index]);

                actionResult.Items.Add(item);
            }

            return new ActionResult<Results.GetPromotionalActivityListResult>("1.0", true,
                ErrorCode.NoError,
                ErrorCode.ToString(ErrorCode.NoError),
                actionResult);
        }
    }
}
